package com.wwz.config;

import com.wwz.feign.ProductFeign;
import com.wwz.listener.MyApplicationListener;
import com.wwz.tcc.TccOrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author wwz
 */
public  class MyTaskListener  implements MyApplicationListener<ApplicationEvent> , ApplicationListener<ApplicationEvent>{

    private static final Logger logger = LoggerFactory.getLogger(MyTaskListener.class);

    private static ExecutorService executorService = new ThreadPoolExecutor(10,20,5000L, TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable>(10));
    @Autowired
    private ProductFeign productFeign;
    @Autowired
    private TccOrderService tccOrderService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;



    @Override
    @GlobalTransactional
    public void onApplicationEvent(ApplicationEvent applicationEvent){
        logger.info(applicationEvent.getSource().toString());
        int j =  (int)productFeign.update("5","1");
        int i =  tccOrderService.insert(null,"44",System.currentTimeMillis());

    }
}
